﻿package src {
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	/**
	 * A Tab class to be extended by all tabs.
	 * @author Indrek Tamming
	 */
	public class Tab extends Sprite {
		
		/**
		 * Tab constructor, no code inside
		 */
		public function Tab():void {
			
		}
		
		/**
		 * Draw a formatted textfield
		 * @param	_text	-	text to put into the field
		 * @param	_x		-	fields x coordinate
		 * @param	_y		-	fields y coordinate
		 * @param	_bold	-	use bold text?
		 * @param	_size	-	text size, default is 10	
		 * @return			-	the TextField object
		 */
		public function drawLabel(_text:String, _x:Number = 0, _y:Number = 0, _bold:Boolean = true, _size = 10):TextField {
			var tf:TextField = new TextField();
			tf.x = _x;
			tf.y = _y
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.selectable = false;
			tf.defaultTextFormat = new TextFormat("Arial", _size, 0, _bold);
			tf.text = _text;
			return tf;
		}
		
		/**
		 * Draw a simple rectangular button
		 * @param	_x				-	buttons x coordinate
		 * @param	_y				-	buttons y coordinate
		 * @param	_clickListener	-	function to listen MouseEvent.CLICK event
		 * @return					-	the button on a Sprite object
		 */
		public function drawButton(_x:Number, _y:Number, _clickListener:Function):Sprite {
			var s:Sprite = new Sprite();
			s.x = _x;
			s.y = _y;
			s.buttonMode = true;
			var g:Graphics = s.graphics;
			g.lineStyle(2);
			g.beginFill(0xFFFFFF);
			g.drawRect(0, 0, 12, 12);
			g.endFill();
			s.filters = [new DropShadowFilter(2,45,0,0.5,4,4,0.5,1)];
			s.addEventListener(MouseEvent.CLICK, _clickListener);
			s.addEventListener(MouseEvent.MOUSE_OVER, btnMouseOver);
			s.addEventListener(MouseEvent.MOUSE_OUT, btnMouseOut);
			return s;
		}
		
		/**
		 * Mouse over event listener for simple button
		 * @param	e	-	the event
		 */
		private function btnMouseOver(e:MouseEvent):void {
			e.target.filters = [new DropShadowFilter(4,45,0,0.75,6,6,0.75,1)];
		}
		
		/**
		 * Mouse out event listener for simple button
		 * @param	e	-	the event
		 */
		private function btnMouseOut(e:MouseEvent):void {
			e.target.filters = [new DropShadowFilter(2,45,0,0.66,4,4,0.66,1)];
		}
		
	}
	
}